package com.cg.controller;


import com.cg.dto.AddLikeDTO;
import com.cg.dto.AddQuestionDTO;
import com.cg.dto.UpdateQuestionDTO;
import com.cg.entity.Question;
import com.cg.result.R;
import com.cg.service.IQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 加
 * @since 2025-01-17
 */
@CrossOrigin
@RestController
@Api(value = "questionController",description = "欢迎来到问题管理",tags = "问题管理")
@RequestMapping("/api/question")
public class QuestionController {
    @Autowired
    private IQuestionService questionService;

    @ApiOperation("新增收藏")
    @PostMapping("/addLike")
    public R addLike(AddLikeDTO addLikeDTO){
        return questionService.addLike(addLikeDTO);
    }

    @GetMapping("/showQuestion")
    @ApiOperation("展示所有问题")
    public R<List<Question>> showQuestion(){
        return questionService.showQuestion();
    }

    @PostMapping("/getQuestionDetail")
    @ApiOperation("问题详情")
    public R getQuestionDetail(@RequestParam("questionId")Long questionId){
        return questionService.getQuestionDetail(questionId);
    }

    @PostMapping("/addQuestion")
    @ApiOperation("新增问题")
    public R addQuestion( AddQuestionDTO addQuestionDTO){
        return questionService.addQuestion(addQuestionDTO);
    }

    @PutMapping("/updateQuestion")
    @ApiOperation("更新题目")
    public R updateQuestion( UpdateQuestionDTO updateQuestionDTO){
        return questionService.updateQuestion(updateQuestionDTO);
    }

    @DeleteMapping("/deleteQuestion")
    @ApiOperation("删除题目")
    public R deleteQuestion(@RequestParam("questionId") Long questionId){
        return questionService.deleteQuestion(questionId);
    }


}
